/**
 * Google登錄包装器
 * 在Expo Go中显示提示，在Development Build中使用真实功能
 */

import { Alert } from 'react-native';
import Constants from 'expo-constants';

// 检查是否在Development Build环境中
const isDevBuild = Constants.appOwnership === 'standalone' || Constants.executionEnvironment === 'standalone';
const isExpoGo = Constants.appOwnership === 'expo' && Constants.executionEnvironment === 'storeClient';

export class GoogleAuthWrapper {
  /**
   * 执行Google登錄
   */
  static async signIn() {
    // 在Expo Go中显示提示
    if (isExpoGo) {
      return new Promise((resolve, reject) => {
        Alert.alert(
          'Google登录不可用',
          'Google登录功能需要在Development Build或生产版本中使用，Expo Go不支持此功能。\n\n要测试Google登录，请：\n1. 运行: eas build --platform android --profile development\n2. 安装生成的APK文件\n3. 在真机上测试',
          [
            {
              text: '取消',
              style: 'cancel',
              onPress: () => reject(new Error('用户取消')),
            },
            {
              text: '了解更多',
              onPress: () => {
                // 可以打开文档链接
                reject(new Error('需要Development Build'));
              },
            },
          ]
        );
      });
    }

    // 在Development Build中使用真实功能
    try {
      const { GoogleAuthManager } = await import('./googleAuth');
      const res = await GoogleAuthManager.signIn();
      console.log(res,'res==========')
      return res
    } catch (error) {
      console.error('Google登錄模块加载失败:', error);
      throw new Error('Google登錄功能不可用');
    }
  }

  /**
   * 检查是否支持Google登錄
   */
  static isSupported(): boolean {
    return !isExpoGo;
  }

  /**
   * 获取环境信息
   */
  static getEnvironmentInfo() {
    return {
      appOwnership: Constants.appOwnership,
      executionEnvironment: Constants.executionEnvironment,
      isExpoGo,
      isDevBuild,
      supportsGoogle: this.isSupported(),
    };
  }
}
